import { Member } from "./member";

export class Team {
    private index:number;
    private members:Array<Member>;
    constructor(index:number){
        this.index = index;
        this.members = new Array<Member>();
    }
    public add(member:Member){
        this.members.push(member);
    }
    public remove(member:Member){
        let index = this.members.indexOf(member);
        this.members.splice(index,1);
    }
    public removeById(id:number):Member|null{
        for(let i=0;i<this.members.length;++i){
            if(this.members[i].getId() == id){
                return this.members.splice(i,1)[0];
            }
        }
        return null;
    }
    public getNum():number{
        return this.members.length;
    }
    public getIndex():number{
        return this.index;
    }
    public setIndex(index:number){
        this.index = index;
    }
    public getMembers():Array<Member>{
        return this.members;
    }
    public getMember(id:number):Member|null{
        for(let i=0;i<this.members.length;++i){
            if(this.members[i].getId() == id){
                return this.members[i];
            }
        }
        return null;
    }
    public clear(){
        this.members.length = 0;
    }
}